{extend name="common/base" /}
{block name="body"} 
<style>
    .slect_dropdown_box{
        height: 300px;
        overflow-y: auto;
    }
</style>
<main>

    <div class="container address-and-delivery layui-row">
        <div class="layui-col-md3 layui-col-xs12 personal-nav">
            <div class="personal-user-name">
                <h1>Welcome Back,<br>{$user_info.first_name}</h1>
                <p class="white-font">{$user_info.email}</p>
            </div>

            <div class="personal-nav-item">
                <p class="white-font font-size-small">PURCHASE HISTORY</p>
                <div class="unselect-button">
                    <a href="/personal-info-all-purchases.html">
                        <span>personal-info-all-purchases.html#block</span>
                        <img src="__ROOT__/static/images/part2-go.png" alt="">
                    </a>

                </div>
            </div>
            <div class="personal-nav-item">
                <p class="white-font font-size-small">PROFILE</p>
                <div class="unselect-button">
                    <a href="/personal-my-sizes.html">
                        <span>My Sizes</span>
                        <img src="__ROOT__/static/images/part2-go.png" alt="">
                    </a>
                </div>
                <div class="unselect-button">
                    <a href="/personal-info.html">
                        <span>Personal Info</span>
                        <img src="__ROOT__/static/images/go-white.png" alt="">
                    </a>
                </div>
                <div class="unselect-button">
                    <a href="/personal-payments.html">
                        <span>Payments</span>
                        <img src="__ROOT__/static/images/part2-go.png" alt="">
                    </a>
                </div>
                <div class="select-button">
                    <a href="/personal-address-and-delivery.html">
                        <span>Address and Delivery</span>
                        <img src="__ROOT__/static/images/part2-go.png" alt="">
                    </a>
                </div>
            </div>
            <div class="personal-nav-item">
                <p class="white-font font-size-small">SECURITY AND COMMUNICATION</p>
                <div class="unselect-button">
                    <a href="/personal-change-password.html">
                        <span>Change Password</span>
                        <img src="__ROOT__/static/images/part2-go.png" alt="">
                    </a>
                </div>
                <div class="unselect-button">
                    <a href="/personal-subsc-riptions.html">
                        <span>Subsc riptions</span>
                        <img src="__ROOT__/static/images/part2-go.png" alt="">
                    </a>
                </div>

                <div class="unselect-button margin-top-sign-out">
                    <a href="/login_out.html">
                        <span>Sign Out</span>
                        <img src="__ROOT__/static/images/part2-go.png" alt="">
                    </a>
                </div>
            </div>
        </div>
        <div class="layui-col-md9 layui-col-xs12 personal-genter" id="block">
            <h1 class="personal-genter-title">Address and Delivery</h1>
            <ul class="layui-row layui-col-space30">
                <li class="layui-col-md12 layui-col-xs12">
                    <label class="personal-label" for="unit number，street">unit number，street</label>
                    <!-- <p class="personal-value">34A3333333333333</p> -->
                    <div class="input-style">
                        <input type="text" name="street" value="{$user_info.street|default=''}">
                    </div>
                </li>
                <li class="layui-col-md12 layui-col-xs12">
                    <label class="personal-label" for="city-suburb">city，suburb</label>
                    <!-- <p class="personal-value">2024-9-9</p> -->
                    <div class="input-style">
                        <input type="text" name="city" value="{$user_info.city|default=''}">
                    </div>
                </li>
                <li class="layui-col-md12 layui-col-xs12">
                    <label class="personal-label" for="description">description</label>
                    <!-- <p class="personal-value">AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</p> -->
                    <div class="input-style">
                        <input type="text" name="description" value="{$user_info.description|default=''}">
                    </div>
                </li>
                <li class="layui-col-md6 layui-col-xs12 ">
                    <label class="personal-label" for="description">State</label>
                    <!-- <p class="personal-value">34A3333333333333</p> -->
                    <div class="input-style">
                        <input type="text" name="state" value="{$user_info.state|default=''}">
                    </div>
                </li>
                <li class="layui-col-md6 layui-col-xs12 ">
                    <label class="personal-label" for="description">Postcode</label>
                    <!-- <p class="personal-value">34A3333333333333</p> -->
                    <div class="input-style">
                        <input type="text" name="post_code" value="{$user_info.post_code|default=''}">
                    </div>
                </li>
                <li class="layui-col-md12 layui-col-xs12 flex-end">
                    <div class="submit-button" id="save_update">
                        Save Update
                    </div>
                </li>
            </ul>

        </div>
    </div>
</main>
{/block}

{block name="js"} 
<script>
    $(function () {
       

        // Register button click event
        $('#save_update').on('click', function () {
            const street = $('input[name="street"]').val();
            const city = $('input[name="city"]').val();
            const description = $('input[name="description"]').val();
            const state = $('input[name="state"]').val();
            const post_code = $('input[name="post_code"]').val();

            if (!street) {
                return layui.layer.msg('Street is Required', {icon: 2});
            }
            if (!city) {
                return layui.layer.msg('City is Required', {icon: 2});
            }
            if (!description) {
                return layui.layer.msg('Description is Required', {icon: 2});
            }
            if (!state) {
                return layui.layer.msg('State is Required', {icon: 2});
            }
            if (!post_code) {
                return layui.layer.msg('Post Code is Required', {icon: 2});
            }


            // Submit form
            const data = {
                street: street,
                city: city,
                description: description,
                state: state,
                post_code: post_code
            };
            
            ajaxRequest('/personal-address-and-delivery', data, 'POST', this, function (response) {
                layer.msg('UPDATE SUCCESS', {icon: 1, time: 2000}, function() {
                    // 弹窗消失后跳转
                    window.location.href = '/personal-address-and-delivery'; // 替换为目标页面的 URL
                });
            });
        });


    });
</script>
{/block}
